home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH15 / DELETE.ASM < prev    next >
Encoding:
Assembly Source File  |  1996-02-25  |  1.5 KB  |  73 lines

  1. ; DELETE - removes some substring from a string.
  2. ;
  3. ; On entry:
  4. ;
  5. ; DS:SI            Points at the source string.
  6. ; DX            Index into the string of the start of the substring
  7. ;            to delete.
  8. ; CX            Length of the substring to be deleted.
  9. ;
  10. ; Error conditions-
  11. ;
  12. ; If DX is greater than the length of the string, then the
  13. ; operation is aborted.
  14. ;
  15. ; If DX+CX is greater than the length of the string, DELETE only
  16. ; deletes those characters from DX through the end of the string.
  17.  
  18. DELETE        proc    near
  19.         push    es
  20.         push    si
  21.         push    di
  22.         push    ax
  23.         push    cx
  24.         push    dx
  25.         pushf            ;Save direction flag.
  26.         mov    ax, ds        ;Source and destination strings
  27.         mov    es, ax        ; are the same.
  28.         mov    ah, 0
  29.         mov    dh, ah        ;Just to be safe.
  30.         mov    ch, ah
  31.  
  32. ; See if any error conditions exist.
  33.  
  34.         mov    al, [si]    ;Get the string length
  35.         cmp    dl, al        ;Is the index too big?
  36.         ja    TooBig
  37.         mov    al, dl        ;Now see if INDEX+LENGTH
  38.         add    al, cl        ;is too large
  39.         jc    Truncate
  40.         cmp    al, [si]
  41.         jbe    LengthIsOK
  42.  
  43. ; If the substring is too big, truncate it to fit.
  44.  
  45. Truncate:    mov    cl, [si]        ;Compute maximum length
  46.         sub    cl, dl
  47.         inc    cl
  48.  
  49. ; Compute the length of the new string.
  50.  
  51. LengthIsOK:    mov    al, [si]
  52.         sub    al, cl
  53.         mov    [si], al
  54.  
  55. ; Okay, now delete the specified substring.
  56.  
  57.         add    si, dx        ;Compute address of the substring
  58.         mov    di, si        ; to be deleted, and the address of
  59.         add    di, cx        ; the first character following it.
  60.         cld
  61.     rep    movsb            ;Delete the string.
  62.  
  63. TooBig:        popf
  64.         pop    dx
  65.         pop    cx
  66.         pop    ax
  67.         pop    di
  68.         pop    si
  69.         pop    es
  70.         ret
  71. DELETE        endp
  72.  
  73.